﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Touch2Like.Model;
using System.Data;

namespace Touch2Like.DAL
{
    public class Customer
    {
        #region Get By Email
        public CustomerInfo GetByEmail(string email)
        {
            Database db = new Database();
            SqlDataReader dr = null;
            SqlParameter[] param =
                {
                   db.MakeInParam("@Email",SqlDbType.NVarChar,100, email)
                };

            try
            {
                dr = db.RunProc("Touch_Customer_GetByEmail", param);

                if (dr.Read())
                {
                    CustomerInfo info = new CustomerInfo();

                    info.CustomerID = DataHelper.GetInt(dr["CustomerID"]);
                    info.CustomerGUID = DataHelper.GetString(dr["CustomerGUID"]);
                    info.CustomerLevelID = DataHelper.GetInt(dr["CustomerLevelID"]);
                    info.Email = DataHelper.GetString(dr["Email"]);
                    info.Password = DataHelper.GetString(dr["Password"]);
                    info.SaltKey = DataHelper.GetInt(dr["SaltKey"]);
                    info.FirstName = DataHelper.GetString(dr["FirstName"]);
                    info.LastName = DataHelper.GetString(dr["LastName"]);
                    info.Phone = DataHelper.GetString(dr["Phone"]);

                    return info;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
                db.Close();
            }
        }
        #endregion
    }
}
